//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet.Data
{
    public class Tables: IOfficeXmlSerializable
    {
        readonly List<IOfficeXmlSerializable> _items = new List<IOfficeXmlSerializable>();
        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (var c = context.Read("tables"))
            {
                while (c.ReaderLocalName != null)
                {
                    switch (c.ReaderLocalName)
                    {
                        case "x":
                            _items.Add(c.ReadElement<Index>());
                            break;
                        case "m":
                            _items.Add(c.ReadElement<TableMissing>());
                            break;
                        case "s":
                            _items.Add(c.ReadElement<StringValue>());
                            break;

                            default: throw new NotSupportedException(c.ReaderLocalName);
                    }
                }
            }

        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (var c = context.Write("tables"))
            {
                foreach (var item in _items)
                {
                    c.WriteElement(item);
                }
            }
        }

        #endregion
    }
}
